package neuralmusic.brain;

import java.util.TreeSet;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.TimeUnit;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import neuralmusic.brain.module.BasicDelayed;
import neuralmusic.brain.module.Scheduler;
import neuralmusic.brain.module.Neuron;


public class InstantScheduler  extends Scheduler{

	
	double currentTime=0.0;
	
	TreeSet<BasicDelayed> tree=new TreeSet<BasicDelayed>();

	private boolean stopped;
	
	
	public InstantScheduler() {
		
	}
	
	
	@Override
	public double getCurrentTimeInSecs() {
		
		return currentTime;
	}

	@Override
	public BasicDelayed take() throws InterruptedException {
		
		BasicDelayed n=tree.first();
		tree.remove(n);
		double currentTime1=n.getWhen();
		
		assert(currentTime1 >= currentTime);
		currentTime = currentTime1;
	//	System.out.println(" TAKE AT "+ currentTime);
		return n;
	}

	@Override
	public void add(BasicDelayed neuron) {
		tree.add(neuron);
		
	}

	@Override
	public long getDelay(TimeUnit unit, double triggerInSecs) {
		throw new NotImplementedException();
//		
//		long t = (long)((triggerInSecs - ref.getCurrentTimeInSecs())*1e6);
//		
//		return unit.convert(t, TimeUnit.MICROSECONDS);		
	}

	@Override
	public int size() {
		
		return tree.size();
	}


	

}

